import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:pass_log/app/core/utils/adapt.dart';
import 'package:pass_log/app/data/providers/app_version.dart';
import 'package:pass_log/app/data/services/theme_service.dart';
import 'package:pass_log/app/modules/home/widgets/home_appbar.dart';

import '../home_controller.dart';

// class HomeDrawerController extends GetxController {}

class HomeDrawer extends StatelessWidget {
  const HomeDrawer({super.key});

  static final appVerCtr = Get.find<AppVersionProvider>();
  static final ctr = Get.find<HomeController>();

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            color: ThemeService.to.curColorScheme.primary,
            height: context.mediaQueryPadding.top + const HomeAppBar().preferredSize.height,
            child: Padding(
              padding: EdgeInsets.only(top: Adapt.pt(30)),
              child: Row(
                children: <Widget>[
                  Padding(
                    padding: EdgeInsets.symmetric(horizontal: Adapt.pt(10)),
                    child: Icon(
                      Icons.lock_rounded,
                      size: Adapt.pt(30),
                      color: ThemeService.to.curColorScheme.onPrimary,
                    ),
                  ),
                  Text.rich(TextSpan(children: [
                    TextSpan(
                      text: "PassLog",
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: Adapt.pt(26),
                        color: ThemeService.to.curColorScheme.onPrimary,
                      ),
                    ),
                    TextSpan(
                      text: "    ${appVerCtr.version}",
                      style: TextStyle(
                        fontSize: Adapt.pt(14),
                        color: ThemeService.to.curColorScheme.onPrimary,
                      ),
                    ),
                  ])),
                ],
              ),
            ),
          ),
          Expanded(
            child: ListView(
              padding: EdgeInsets.zero,
              children: <Widget>[
                ListTile(
                  leading: Icon(Icons.bookmark_add, size: Adapt.pt(22)),
                  title: Text("分类管理", style: TextStyle(fontSize: Adapt.pt(16))),
                  onTap: () async {
                    Scaffold.of(context).closeDrawer();
                    await Get.toNamed("/type");
                    ctr.refreshMainList();
                  },
                ),
                ListTile(
                  leading: Icon(Icons.settings, size: Adapt.pt(22)),
                  title: Text("系统设置", style: TextStyle(fontSize: Adapt.pt(16))),
                  onTap: () {},
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
